package com.gold.security;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.gold.model.User;
import com.gold.util.CurrentSession;

@Aspect
@Component("logUtilService")
public class LogAspect {
    private final static Logger logger = LoggerFactory.getLogger(LogAspect.class);
    static {
        System.out.println("LogAspect 被加载了----------");
    }

    //@Before("execution(public * com.apay.utils.MsgUtils.sendMsg(..))")
    public void doAfterSendMsg(JoinPoint jp) {
        try {
            String phoneNo = (String) jp.getArgs()[0];
            String methodName = jp.getSignature().getName();
            String className = jp.getTarget().getClass().getSimpleName();
            String target = jp.getTarget().toString();
            System.out.println("phoneNo----------"+phoneNo);
            System.out.println("methodName----------"+methodName);
            System.out.println("className----------"+className);
            System.out.println("target----------"+target);


        } catch (Exception e) {
            // TODO Auto-generated catch block
            System.out.println("异常："+e.getMessage());
        }
    }

    @Before("execution(public * com.gold.service.impl.*Impl.add*(..))")
    public void doBeforeAdd(JoinPoint jp) {
        try {
            User staffInfo = (User)CurrentSession.getSession();
            String operator = null==staffInfo?"null":staffInfo.getuName();
            Object obj = jp.getArgs()[0];
            String methodName = jp.getSignature().getName();
            String className = jp.getTarget().getClass().getSimpleName();
            String target = jp.getTarget().toString();
            logger.info("operator"+operator);
            logger.info("methodName----------" + methodName);
            logger.info("className----------" + className);
            logger.info("params----------"+obj.toString());
            logger.info("target----------" + target);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            logger.debug("异常：", e.getMessage());
        }
    }


}
